package com.tian.hello.ui;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.tian.hello.R;
import com.tian.hello.ipc.client.ClientActivity;
import com.tian.hello.srollview.ListViewTestAc;
import com.tian.hello.ui.mgroupview.CustomViewActivity;
import com.tian.hello.ui.qqfriend.QQActivity;
import com.tian.hello.ui.topline.ComplexListActivity;

//@DIActivity()
//@Test(path = "main")
public class MainActivity extends AppCompatActivity {
    private Button btn_two, btn_three, btn_four, btn_scroll;

    //    @BYView(R.id.btn_one)
    public Button btn_one;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        ManagerFindByMainActivity.findById(this);
        init();
        registerReceiver();
    }

    private void init() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        btn_one = findViewById(R.id.btn_one);
        btn_two = findViewById(R.id.btn_two);
        btn_three = findViewById(R.id.btn_three);
        btn_four = findViewById(R.id.btn_four);
        btn_scroll = findViewById(R.id.btn_scroll);

        btn_one.setOnClickListener(v -> {
                    startActivity(new Intent(MainActivity.this, CustomViewActivity.class));
                }
        );

        findViewById(R.id.btn_action).setOnClickListener(v -> {
                    startActivity(new Intent(MainActivity.this, ViewActionTestAc.class));
                }
        );


        btn_two.setOnClickListener(v -> {
            startActivity(new Intent(MainActivity.this, ComplexListActivity.class));
        });

        btn_three.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, QQActivity.class)));

        btn_four.setOnClickListener((view) -> {
            startActivity(new Intent(MainActivity.this, ClientActivity.class));
        });

        findViewById(R.id.btn_apt).setOnClickListener(v -> startActivity(new Intent(MainActivity.this, AptActivity.class)));
        findViewById(R.id.btn_aop).setOnClickListener(v -> startActivity(new Intent(MainActivity.this, AopTestAc.class)));

        btn_scroll.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, ListViewTestAc.class)));
    }


    /**
     * 广播接收器
     */
    private BroadcastReceiver netWorkChangeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("Test_Main", "网络发生变化-" + "aciton:" + intent.getAction() + "-当前版本" + android.os.Build.VERSION.SDK_INT);
        }
    };

    private void registerReceiver() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
        filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        registerReceiver(netWorkChangeReceiver, filter);
    }

    private void unRegisterReceiver() {
        unregisterReceiver(netWorkChangeReceiver);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unRegisterReceiver();
    }
}
